<style type="text/css">
    .layui-table-body{overflow-x:auto;}
    .layui-table-cell{font-size:12px;}
</style>
<table id="dataTable" lay-filter='dataTable'></table>

<script type="text/html" title="操作按钮模板" id="buttonTpl">
    <a href="{:url('fx_goods_edit')}?id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-normal hisi-iframe-pop"  hisi-data="{width: '1000px', height: '500px', title: '设置佣金'}">设置佣金</a>
    <!-- <a href="{:url('del')}?type=goods&id={{ d.id }}" class="layui-btn layui-btn-xs layui-btn-danger j-tr-del">删除</a> -->
</script>

<script type="text/html" title="状态模板" id="statusTpl">
    <input type="checkbox" name="is_fenxiao" value="{{ d.is_fenxiao }}" lay-skin="switch" lay-filter="switchStatus" lay-text="参与|不参与" {{ d.is_fenxiao == 1 ? 'checked' : '' }}  data-href="{:url('is_fenxiao')}?id={{ d.id }}">
</script>
{include file="system@block/layui" /}
<script id="toolbar" type="text/html">
    <a href="{:url('add')}?type=goods" class="layui-btn layui-btn-normal layui-btn-sm hisi-iframe-pop" hisi-data="{width: '1000px', height: '500px', title: '添加商品'}">&nbsp;添加</a>
    <a href="{:url('goods_export')}" class="layui-btn layui-btn-primary layui-icon layui-icon-play" width="460" height="270">&nbsp;导出</a>
    <button type="button" class="layui-btn" id="test1">
        <i class="layui-icon">&#xe67c;</i>导入excel
      </button>
</script>
<script type="text/javascript">
    layui.use(['table'], function() {
        var table = layui.table;
        table.render({
            elem: '#dataTable'
            ,url: '{:url()}' //数据接口
            ,page: true //开启分页
            ,skin: 'row'
            ,even: true
            ,limit: 20
            ,text: {
                none : '暂无相关数据'
            }
            // ,toolbar: '#toolbar'
            ,defaultToolbar: ['filter']
            ,cols: [[ //表头
                {field: 'id', title: 'ID'}
                ,{field: 'jifen_price_inner', title: '每消费多少元',edit:'text'}
                ,{field: 'jifen_inner', title: '可获取多少积分',edit:'text'}
            ]]
            ,done: function(){
                if (typeof(layui.global.addTableTool) !== 'undefined') {
                    layui.global.addTableTool();
                }
            }
        });

        table.on('edit(dataTable)', function(obj){
            var $ = layui.jquery
            var newValue = obj.value;
            var changeField = obj.field;
            var id = obj.data.id;
            if(!!isNaN(newValue)){
                layer.alert('佣金比例需为数字');
                return false;
            }
            $.ajax({
                type:"post",
                url:"{:url('changeConfig3')}",
                async:false,
                data:{val:newValue,field:changeField,id:id},
                success:function(data){
                    // console.log(data);
                    if(data.code==200){
                        layer.msg('修改成功');
                    }
                    else{
                        layer.msg(data.msg);
                    }
                },
                error: function(){
                    layer.alert("预警值查询错误！");
                }
            })
            console.log(obj.value);
            console.log(obj.field);
            console.log(obj.data);
        })
    });

    layui.use('upload', function(){
        var upload = layui.upload; //得到 upload 对象
        //创建一个上传组件
        upload.render({
        elem: '#test1'
        ,url: '{:url("goods_import")}'
        ,method:'post'
        ,done: function(res){ //上传后的回调
            // console.log(res);
            if(res.status=='success'){
                layer.msg('导入成功');
                window.location.reload();
            }
            else{
                layer.msg(res.msg);
            }
        } 
        ,accept: 'file' //允许上传的文件类型
        //,size: 50 //最大允许上传的文件大小
        //,……
        })
    });
</script>